package com.rui.cn.provider.service.system.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rui.cn.entity.system.SysRoleMenu;
import com.rui.cn.provider.repository.system.SysRoleMenuDao;
import com.rui.cn.provider.service.system.SysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 角色菜单 服务实现类
 * </p>
 *
 * @author zhang123
 * @since 2018-01-14
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuDao,SysRoleMenu> implements SysRoleMenuService {
    @Autowired
    private SysRoleMenuDao sysRoleMenuDao;
    @Override
    public Integer saveRoleMenu(Integer[] ids, Integer roleid) {
        Integer flag=0;
        //先删除角色的所有菜单
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("roleid",roleid);
        sysRoleMenuDao.deleteByMap(map);
        for (Integer menuid:ids){
            if (menuid==0){
                continue;
            }
            flag+=sysRoleMenuDao.insert(new SysRoleMenu(menuid,roleid));
        }
        return flag;
    }
}
